﻿<%@ Page Title="" Language="C#" MasterPageFile="AdminSite.Master" AutoEventWireup="true"
    CodeBehind="AboutContentPage.aspx.cs" Inherits="phudieuhungthinh.Admin.AboutContentPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="/Styles/control-style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../third-party/tiny_mce/jquery.tinymce.js"></script>
    <script type="text/javascript" src="../third-party/tiny_mce/loadTinyMce.js"></script>
    <style type="text/css">
        .error-message
        {
            color: Blue;
        }
        .btn-submit
        {
            background-color: #ccc;
            color: black;
            font-family: 'Oswald';
            font-size: 20px;
            text-decoration: none;
            cursor: pointer;
            border: none;
        }
    </style>
    <script type="text/javascript">
    $(function () {
        loadTinyMce();
    });
    $(document).ready(function () {
        function articleModel() {
            var self = this;
            self.description = ko.observable();
            var id = 0;
            $.ajax({
                type: "POST",
                url: location.pathname + '/Get',
                dataType: "json",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    if (data.d == null) {
                    }
                    else {
                        self.description = ko.observable(data.d.ArticleContent);
                        id = data.d.ID;
                    }
                },
                error: function (xmlHttpRequest) {
                    var ex = eval("(" + xmlHttpRequest.responseText + ")");
                    alert("failed\nDetail: " + ex.Message);
                }
            });
            self.save = function() {
                var model = {
                    ID: id,
                    ArticleContent: $('#txtaDescription').tinymce().getContent()
                };
                $.ajax({
                    type: "POST",
                    url: location.pathname + '/SaveArticle',
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify({ articleModel: model }),
                    success: function() {
                        $('.error-message').remove();
                        $('#s-message').append("<span class='error-message'>Lưu thành công.</span>");
                        //Auto hide after 4 seconds.
                        $('.error-message').delay(4000).fadeOut('slow');
                    },
                    error: function (xmlHttpRequest) {
                        var ex = eval("(" + xmlHttpRequest.responseText + ")");
                        alert("failed\nDetail: " + ex.Message);
                    }
                });
            };
        }
        ko.applyBindings(new articleModel());
    });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="content">
        <fieldset>
            <legend>Giới thiệu</legend>
            <div>
                <div>
                    Về Chúng tôi:
                </div>
                <div style="margin-top: 20px">
                    <textarea id="txtaDescription" style="height: 300px; width: 900px" class="tinymce"
                        rows="10" cols="2" data-bind="value: description"></textarea>
                </div>
            </div>
            <div class="button save" style="margin-top: 20px">
                <a href="javascript:void(0)" data-bind="click: save">Lưu</a>
            </div>
            <span id="s-message"></span>
        </fieldset>
    </div>
</asp:Content>
